import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import glsl from 'vite-plugin-glsl'
import path from "path";
import { templateCompilerOptions } from '@tresjs/core'
import UnoCSS from 'unocss/vite'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({
  base: process.env.NODE_ENV === "production" ? "/h5/tres" : "/",
  plugins: [
    vue({
      ...templateCompilerOptions,
    }),
    Components({
      resolvers: [VantResolver()],
    }),
    UnoCSS(),
    glsl(),
  ],
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          three: ['three'],
        },
      },
    },
  },
  optimizeDeps: {
    exclude: ['vue', 'three'],
  },
  resolve: {
    alias: {
      "/@": path.resolve(__dirname, "src"), // 使用绝对路径
      "/#": path.resolve(__dirname, "types"), // 使用绝对路径
    },
  },
  server: { 
    // https: {
    //   key: fs.readFileSync('./mkcert/ca.key'),
    //   cert: fs.readFileSync('./mkcert/ca.crt'),
    // },
    host: '0.0.0.0',
   }
})

